<%@page import="com.DAO.CategoryDAO"%>
<%@page import="com.DAO.UserDAO"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="com.beans.*,java.util.*"%>
 <%@taglib prefix="html" uri="/tags/struts-html" %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel = "stylesheet" href = "style/Global.css">
</head>
<body>
	 <%!  int notice_id; %>
	<% 
    NoticeForm noticeForm=(NoticeForm)session.getAttribute("noticeform");

    notice_id=noticeForm.getNoticeId();
    String title=noticeForm.getTitle();
	String description=noticeForm.getDescription();
	String creatorid=noticeForm.getCreatorId();
	String creatorname=noticeForm.getCreatorName();
	Date date = noticeForm.getCreatedDate();
	
	CategoryDAO catdao=new CategoryDAO();
	
	String allowComments=catdao.getCategoryInfo(noticeForm.getCategoryId()).getAllowComment();
	
	request.setAttribute("notice_id",notice_id);
	
%>
	<div id = "noticeview">
		<div id = "noticeheading">
			<span id = "noticetitle">
				<%=title%>
			</span>
				<%			if((session.getAttribute("userid").toString().equals(creatorid)) ||
						(session.getAttribute("user_type").toString().equals("admin")))
						{ %>
			<a class = "btndelete" href = "DeleteNoticeAction.do?notice_id=<%=notice_id%>" >X</a>&nbsp;&nbsp;
			<%} %>
			
			<span id = "createddate">
				on&nbsp;<%=date %>&nbsp;&nbsp;
			</span>
			<span id = "creatorname">
				by&nbsp; <%=creatorname %>&nbsp;
			</span>			
			
		</div>
		<br>
		<div id = "description"><%=description %></div>
	</div>
	
	<%
	  //make changes
	if(allowComments.equals("T")) {    %>
	
	
	<form id = "commentform" action="CommentForm.do?notice_id=<%=notice_id%>" method="post">
	<div id = "addcomment">Add Comment</div>
	<textarea id = "txtcomment" type = "text" name="description" rows="2"></textarea>
	<html:errors/>
	<br>
	<div>
		<input id = "btnsubmit" type="submit" name = "submit" value = "Submit">
	</div>
	</form>
	
	<div id = "commentonnotice">
	<%!ArrayList<CommentForm> alist=null; %>
<% 
   alist=(ArrayList<CommentForm>)request.getAttribute("listComments");
%>	<span id = "comhead">Comments: </span>
	<ul>
		<%
			for (CommentForm commentForm :alist) {
				int cid=commentForm.getId();
				String desc = commentForm.getDescription();
				String notice_creatorid = commentForm.getCreatedById();
				String comment_creator = (new UserDAO()).getUsernameById(notice_creatorid );
				String expdate = commentForm.getCreatedDate().toString();
				String d[]=expdate.split("-");
				expdate=d[2]+"/"+d[1]+"/"+d[0];
		%>
			
		<li>
			<div class = "commentheading">
			<div class = "commentedby"><%=comment_creator%></div>
			
				<%			if((session.getAttribute("userid").toString().equals(notice_creatorid)) ||
						(session.getAttribute("user_type").toString().equals("admin")))
						{ %>
	<form method="post" id= action="DeleteComment.do?cid=<%=cid%>">					
	      <input class = "btndelete" type="submit" value="X">
	</form>	
<%	}%>
	<div class = "createdon"><%=expdate %>&nbsp;&nbsp;&nbsp;</div>
			</div>
			
			<div class = "commenttext"><%=desc%> </div>
		</li>
		<%}%>
	</ul>
	</div>
	<%} %>
</body>
</html>